home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Precision Software Appli…tions Silver Collection 1
/
Precision Software Applications Silver Collection Volume One (PSM) (1993).iso
/
windows
/
games
/
eyes.arj
/
EYES.OLD
< prev
Wrap
Text File
|
1988-11-11
|
8KB
|
306 lines
/********************************************************************\
EyeWatch -- Cursor Tracking Program.
Written By: Paul L. Yao & Malcolm Austin
\********************************************************************/
#include "windows.h"
#include <math.h>
static HANDLE hInst;
static HWND hWnd;
static HWND hWnd1;
static HWND hWnd2;
POINT pt;
POINT ptOld;
RECT rOldEye1;
RECT rOldEye2;
HBRUSH hWhiteBrush;
HBRUSH hBlackBrush;
HPEN hWhitePen;
char acMainWndProc[] = "MainEyes";
char acEyeWndProc[] = "PlyEyes";
long FAR PASCAL MainWinProc (HWND, unsigned, WORD, LONG);
long FAR PASCAL EyeWinProc (HWND, unsigned, WORD, LONG);
int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
HANDLE hInstance, hPrevInstance;
LPSTR lpszCmdLine;
int cmdShow;
{
MSG msg;
RECT r;
if (!hPrevInstance)
{
WNDCLASS rClass;
rClass.lpszClassName = acMainWndProc;
rClass.hInstance = hInstance;
rClass.lpfnWndProc = MainWinProc;
rClass.hCursor = LoadCursor(NULL, IDC_ARROW) ;
rClass.hIcon = NULL;
rClass.lpszMenuName = NULL;
rClass.hbrBackground = hWhiteBrush;
rClass.style = CS_HREDRAW|CS_VREDRAW;
rClass.cbClsExtra = 0;
rClass.cbWndExtra = 0;
RegisterClass(&rClass);
rClass.lpszClassName = acEyeWndProc;
rClass.hInstance = hInstance;
rClass.lpfnWndProc = EyeWinProc;
rClass.hCursor = LoadCursor(NULL, IDC_ARROW) ;
rClass.hIcon = NULL;
rClass.lpszMenuName = NULL;
rClass.hbrBackground = hWhiteBrush;
rClass.style = CS_HREDRAW|CS_VREDRAW;
rClass.cbClsExtra = 0;
rClass.cbWndExtra = 0;
RegisterClass(&rClass);
}
else ;
hInst = hInstance;
hWhiteBrush = GetStockObject (WHITE_BRUSH);
hBlackBrush = GetStockObject (BLACK_BRUSH);
hWhitePen = GetStockObject (WHITE_PEN);
hWnd = CreateWindow(acMainWndProc,
"Eyes",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL
);
GetClientRect (hWnd, &r);
hWnd1 = CreateWindow(acEyeWndProc,
NULL,
WS_CHILDWINDOW | WS_VISIBLE,
0,
0,
r.bottom,
r.right/2,
hWnd,
1,
hInstance,
NULL
);
hWnd2 = CreateWindow(acEyeWndProc,
NULL,
WS_CHILDWINDOW | WS_VISIBLE,
r.right/2+1,
0,
r.bottom,
r.right/2,
hWnd,
2,
hInstance,
NULL
);
ShowWindow(hWnd, cmdShow);
SetTimer (hWnd, 1, 100, NULL);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
exit(msg.wParam);
}
/********************************************************************\
\********************************************************************/
long FAR PASCAL EyeWinProc (hWnd, identifier, wParam, lParam)
HWND hWnd;
unsigned identifier;
WORD wParam;
LONG lParam;
{
HDC hDC;
PAINTSTRUCT ps;
RECT r;
POINT pt2;
int xShift;
int yShift;
double dX;
double dY;
double dT;
char ac[100];
switch (identifier)
{
case WM_ERASEBKGND:
GetClientRect (hWnd, &r);
FillRect ((HDC)wParam, &r, hWhiteBrush);
/* Set up mapping mode. */
SetMapMode ((HDC)wParam, MM_ISOTROPIC);
SetViewportOrg ((HDC)wParam, r.right/2, r.bottom/2);
SetWindowExt ((HDC)wParam, 100, 100);
SetViewportExt ((HDC)wParam, r.right, r.bottom);
/* Draw Outline of Eye. */
Ellipse ((HDC)wParam, -49, 42, 49, -42);
break;
case WM_PAINT:
hDC = BeginPaint (hWnd, &ps);
GetClientRect (hWnd, &r);
SetMapMode (hDC, MM_ISOTROPIC);
SetViewportOrg (hDC, r.right/2, r.bottom/2);
SetWindowExt (hDC, 100, 100);
SetViewportExt (hDC, r.right, r.bottom);
/* Use a white pen to ease erasing overhead. */
SelectObject (hDC, hWhitePen);
/* Erase old eye. */
if (hWnd == hWnd1)
Ellipse (hDC,
rOldEye1.left,
rOldEye1.top,
rOldEye1.right,
rOldEye1.bottom);
else
Ellipse (hDC,
rOldEye2.left,
rOldEye2.top,
rOldEye2.right,
rOldEye2.bottom);
/* Determine location of iris. */
pt2 = pt;
ScreenToClient (hWnd, &pt2);
DPtoLP (hDC, &pt2, 1);
dX = (double) pt2.x;
dY = (double) pt2.y;
dT = sqrt ((dX*dX)+(dY*dY));
xShift = (int) ( (20<dT) ? (dX * 20/dT) : dX );
yShift = (int) ( (20<dT) ? (dY * 20/dT) : dY );
/* Draw iris. */
SelectObject (hDC, hBlackBrush);
Ellipse (hDC, -20+xShift, 20+yShift, 20+xShift, -20+yShift);
if (hWnd == hWnd1) {
rOldEye1.left = -20+xShift;
rOldEye1.top = 20+yShift;
rOldEye1.right = 20+xShift;
rOldEye1.bottom = -20+yShift;
}
else {
rOldEye2.left = -20+xShift;
rOldEye2.top = 20+yShift;
rOldEye2.right = 20+xShift;
rOldEye2.bottom = -20+yShift;
}
EndPaint (hWnd, &ps);
break;
default:
return(DefWindowProc(hWnd, identifier, wParam, lParam));
break;
}
return(0L);
}
/********************************************************************\
\********************************************************************/
long FAR PASCAL MainWinProc(hWnd, identifier, wParam, lParam)
HWND hWnd;
unsigned identifier;
WORD wParam;
LONG lParam;
{
HDC hDC;
PAINTSTRUCT ps;
RECT r;
switch (identifier)
{
case WM_CLOSE:
DestroyWindow (hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
hDC = BeginPaint (hWnd, &ps);
if (IsIconic (hWnd)) {
GetClientRect (hWnd, &r);
Rectangle (hDC, 0, 0, r.right, r.bottom);
}
EndPaint (hWnd, &ps);
break;
case WM_PAINTICON:
InvalidateRect (hWnd1, NULL, FALSE);
UpdateWindow (hWnd1);
UpdateWindow (hWnd2);
break;
case WM_ICONERASEBKGND:
hDC = GetDC (hWnd1);
PostMessage (hWnd1, WM_ERASEBKGND, (WORD)hDC, 0L);
ReleaseDC (hWnd, hDC);
hDC = GetDC (hWnd2);
PostMessage (hWnd2, WM_ERASEBKGND, (WORD)hDC, 0L);
ReleaseDC (hWnd, hDC);
break;
case WM_SIZE:
MoveWindow(hWnd1, 0, 0, LOWORD(lParam)/2, HIWORD(lParam), TRUE);
MoveWindow(hWnd2, LOWORD(lParam)/2, 0, LOWORD(lParam)/2, HIWORD(lParam), TRUE);
break;
case WM_TIMER:
GetCursorPos (&pt);
if (ptOld.x != pt.x || ptOld.y != pt.y ) {
InvalidateRect (hWnd1, NULL, FALSE);
InvalidateRect (hWnd2, NULL, FALSE);
if (IsIconic (hWnd)) {
PostMessage (hWnd1, WM_PAINT, 0, 0L);
PostMessage (hWnd2, WM_PAINT, 0, 0L);
}
ptOld.x = pt.x;
ptOld.y = pt.y;
}
break;
default:
return(DefWindowProc(hWnd, identifier, wParam, lParam));
break;
}
return(0L);
}